﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaMusaSoft.RPS.ViewModel.Infrastructure;
using BaMusaSoft.RPS.ViewModel.Properties;
using BaMusaSoft.RPS.RPSServices;
using System.Windows.Input;
using System.ComponentModel;

namespace BaMusaSoft.RPS.ViewModel
{
    class ClaimMarginsViewModel : Workspace
    {
        #region "Fields"
        Settings settings;
        DelegateCommand saveCommand;
        DelegateCommand resetCommand;
        #endregion

        #region "Constructor"
        public ClaimMarginsViewModel()
        {
            settings = Settings.Default;
        }

        #endregion
        
        #region "Properties"
        public float OutboxNoMarginX
        {
            get { return settings.ClaimForm_OutboxNo_X; }
            set
            {
                settings.ClaimForm_OutboxNo_X = value;
                RaisePropertyChanged("OutboxNoMarginX");
            }
        }

        public float OutboxNoMarginY
        {
            get { return settings.ClaimForm_OutboxNo_Y; }
            set
            {
                settings.ClaimForm_OutboxNo_Y = value;
                RaisePropertyChanged("OutboxNoMarginY");
            }
        }

        public float OutboxDateMarginX
        {
            get { return settings.ClaimForm_OutboxDate_X; }
            set
            {
                settings.ClaimForm_OutboxDate_X = value;
                RaisePropertyChanged("OutboxDateMarginX");
            }
        }

        public float OutboxDateMarginY
        {
            get { return settings.ClaimForm_OutboxDate_Y; }
            set
            {
                settings.ClaimForm_OutboxDate_Y = value;
                RaisePropertyChanged("OutboxDateMarginY");
            }
        }

        public float ClaimNoMarginX
        {
            get { return settings.ClaimForm_ClaimNo_X; }
            set
            {
                settings.ClaimForm_ClaimNo_X = value;
                RaisePropertyChanged("ClaimNoMarginX");
            }
        }

        public float ClaimNoMarginY
        {
            get { return settings.ClaimForm_ClaimNo_Y; }
            set
            {
                settings.ClaimForm_ClaimNo_Y = value;
                RaisePropertyChanged("ClaimNoMarginY");
            }
        }

        public float CustomerNameMarginX
        {
            get { return settings.ClaimForm_CustomerName_X; }
            set
            {
                settings.ClaimForm_CustomerName_X = value;
                RaisePropertyChanged("CustomerNameMarginX");
            }
        }

        public float CustomerNameMarginY
        {
            get { return settings.ClaimForm_CustomerName_Y; }
            set
            {
                settings.ClaimForm_CustomerName_Y = value;
                RaisePropertyChanged("CustomerNameMarginY");
            }
        }

        public float ClaimTotalMarginX
        {
            get { return settings.ClaimForm_ClaimTotal_X; }
            set
            {
                settings.ClaimForm_ClaimTotal_X = value;
                RaisePropertyChanged("ClaimTotalMarginX");
            }
        }

        public float ClaimTotalMarginY
        {
            get { return settings.ClaimForm_ClaimTotal_Y; }
            set
            {
                settings.ClaimForm_ClaimTotal_Y = value;
                RaisePropertyChanged("ClaimTotalMarginX");
            }
        }

        public float TotalInWordsMarginX
        {
            get { return settings.ClaimForm_ClaimTotalInWords_X; }
            set
            {
                settings.ClaimForm_ClaimTotalInWords_X = value;
                RaisePropertyChanged("TotalInWordsMarginX");
            }
        }

        public float TotalInWordsMarginY
        {
            get { return settings.ClaimForm_ClaimTotalInWords_Y; }
            set
            {
                settings.ClaimForm_ClaimTotalInWords_Y = value;
                RaisePropertyChanged("TotalInWordsMarginY");
            }
        }
        #region "Claim Details"

        public float DetailRowMarginY
        {
            get { return settings.ClaimForm_DetailRow_Y; }
            set
            {
                settings.ClaimForm_DetailRow_Y = value;
                RaisePropertyChanged("DetailRowMarginY");
            }
        }
        public float DetailRentMarginX
        {
            get { return settings.ClaimForm_DetailRent_X; }
            set
            {
                settings.ClaimForm_DetailRent_X = value;
                RaisePropertyChanged("DetailRentMarginX");
            }
        }
        public float DetailRentPaidMarginX
        {
            get { return settings.ClaimForm_DetailRentPaid_X; }
            set
            {
                settings.ClaimForm_DetailRentPaid_X = value;
                RaisePropertyChanged("DetailRentPaidMarginX");
            }
        }

        public float DetailPropertyMarginX
        {
            get { return settings.ClaimForm_DetailProperty_X; }
            set
            {
                settings.ClaimForm_DetailProperty_X = value;
                RaisePropertyChanged("DetailPropertyMarginX");
            }
        }

        public float DetailMaintMarginX
        {
            get { return settings.ClaimForm_DetailMaint_X; }
            set
            {
                settings.ClaimForm_DetailMaint_X = value;
                RaisePropertyChanged("DetailMaintMarginX");
            }
        }
        public float DetailDepositMarginX
        {
            get { return settings.ClaimForm_DetailDeposit_X; }
            set
            {
                settings.ClaimForm_DetailDeposit_X = value;
                RaisePropertyChanged("DetailDepositMarginX");
            }
        }
        public float DetailOtherMarginX
        {
            get { return settings.ClaimForm_DetailOther_X; }
            set
            {
                settings.ClaimForm_DetailOther_X = value;
                RaisePropertyChanged("DetailOtherMarginX");
            }
        }
        public float DetailRentBalanceMarginX
        {
            get { return settings.ClaimForm_DetailRentBalance_X; }
            set
            {
                settings.ClaimForm_DetailRentBalance_X = value;
                RaisePropertyChanged("DetailRentBalanceMarginX");
            }
        }
        public float DetailArrearRentMarginX
        {
            get { return settings.ClaimForm_DetailArrearRent_X; }
            set
            {
                settings.ClaimForm_DetailArrearRent_X = value;
                RaisePropertyChanged("DetailArrearRentMarginX");
            }
        }
        public float DetailArrearMaintMarginX
        {
            get { return settings.ClaimForm_DetailArrearMaint_X; }
            set
            {
                settings.ClaimForm_DetailArrearMaint_X = value;
                RaisePropertyChanged("DetailArrearMaintMarginX");
            }
        }
        public float DetailTotalMarginX
        {
            get { return settings.ClaimForm_DetailTotal_X; }
            set
            {
                settings.ClaimForm_DetailTotal_X = value;
                RaisePropertyChanged("DetailTotalMarginX");
            }
        }
        public float DetailsGrandTotalMarginX
        {
            get { return settings.ClaimForm_DetailsGrandTotal_X; }
            set
            {
                settings.ClaimForm_DetailsGrandTotal_X = value;
                RaisePropertyChanged("DetailsGrandTotalMarginX");
            }
        }

        public float DetailsGrandTotalMarginY
        {
            get { return settings.ClaimForm_DetailsGrandTotal_Y; }
            set
            {
                settings.ClaimForm_DetailsGrandTotal_Y = value;
                RaisePropertyChanged("DetailsGrandTotalMarginY");
            }
        }
        public float DetailsRowDistance
        {
            get { return settings.ClaimForm_DetailsRowDistance; }
            set
            {
                settings.ClaimForm_DetailsRowDistance = value;
                RaisePropertyChanged("DetailsRowDistance");
            }

        }
        #endregion

        #endregion

        #region "Commands"
        public ICommand SaveCommand
        {
            get
            {
                if (saveCommand == null)
                {
                    saveCommand = new DelegateCommand(par => Save());

                }
                return saveCommand;
            }
        }
        void Save()
        {
            settings.Save();
        }

        public ICommand ResetCommand
        {
            get
            {
                if (resetCommand == null)
                {
                    resetCommand = new DelegateCommand(par => Reset());

                }
                return resetCommand;
            }
        }
        void Reset()
        {
            settings.Reset();
            RefreshBinding();
        }
        #endregion

        #region "Helper methods"

        private void RefreshBinding()
        {
            //Query expression 
            var bindableProperties = from p in typeof(ClaimMarginsViewModel).GetProperties()
                                     where p.GetCustomAttributes(true).Cast<Attribute>().Contains(new BindableAttribute(true))
                                     select p;
            foreach (var p in bindableProperties)
            {
                RaisePropertyChanged(p.Name);
            }
        }
        #endregion

        #region Overrides of Workspace

        public override string DisplayName
        {
            get { throw new NotImplementedException(); }
            protected set { throw new NotImplementedException(); }
        }

        public override bool HasChanges
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
}
